﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ReAnimation.MVP.ViewInterfaces;
using ReAnimation.MVP.Presenters;
using ReAnimation.Helpers.Common;

namespace ReAnimation.MVP.Views
{
    public partial class VideoDialog : BaseFormView, IVideoDialogView
    {
        private VideoDialogPresenter _presenter;
        public VideoDialog(VideoDialogPresenter presenter)
        {
            _presenter = presenter;
            InitializeComponent();
            Init();

            _presenter.View = this;
        }

        private void Init()
        {
            resoulutionsComboBox.DisplayMember = "DisplayMember";
            resoulutionsComboBox.ValueMember = "Value";
            //FIXME: Land of magic values
            resoulutionsComboBox.DataSource = new List<object>() 
            { 
                new {
                    DisplayMember = "640x480",
                    Value = new Size(640,480)
                },
                new {
                     DisplayMember = "800x600",
                     Value = new Size(800,600)
                },
                new {
                    DisplayMember = "1024x768",
                    Value = new Size(1024,768)
                },
                new {
                    DisplayMember = "1280x1024",
                    Value = new Size(1280,1024)
                }
            };
        }

        private void fileDialogBtn_Click(object sender, EventArgs e)
        {
            ChooseFile.Throw(sender, e);
        }

        #region IVideoDialogView Members

        public Size CurrentResolution
        {
            get 
            {
                return (Size)resoulutionsComboBox.SelectedValue;
            }
        }

        public bool SaveFrames
        {
            get 
            {//FIXME:shittttttt
                return saveFramesButton.Title == "Yes";
            }
        }

        public bool UsePov 
        {
            get
            {
                return usePovRayBtn.Title == "Yes";
            }
        }

        public String OutFilePath
        {
            set
            {
                fileNameTextBox.Text = value;
            }
        }

        public Double Duration
        {
            get
            {
                return double.Parse(durationTextBox.Text);
            }
            set
            {
                durationTextBox.Text = value.ToString().Replace(",",".");
            }
        }

        public int Percent { 
            set 
        {
            createVideoProgressBar.Value = value;
            } }

        public event EventHandler ChooseFile;

        public event EventHandler CreateVideo;

        #endregion

        private void saveFramesButton_Click(object sender, EventArgs e)
        {//FIXME: shiiiiiiiiit
            if (saveFramesButton.Title == "Yes")
                saveFramesButton.Title = "No";
            else
                saveFramesButton.Title = "Yes";
        }

        private void usePovRayBtn_Click(object sender, EventArgs e)
        {//FIXME: copy&paste of shit
            if (usePovRayBtn.Title == "Yes")
                usePovRayBtn.Title = "No";
            else
                usePovRayBtn.Title = "Yes";
        }

        private void createVideoButton_Click(object sender, EventArgs e)
        {
            CreateVideo.Throw(sender, e);
        }
    }
}
